---
title: "Reference: createLogger() | Kastrax Observability Docs"
description: Documentation for the createLogger function, which instantiates a logger based on a given configuration.
---

# createLogger() ✅

The `createLogger()` function is used to instantiate a logger based on a given configuration. You can create console-based, file-based, or Upstash Redis-based loggers by specifying the type and any additional parameters relevant to that type.

### Usage

#### Console Logger (Development)

```typescript showLineNumbers copy
const consoleLogger = createLogger({ name: "Kastrax", level: "debug" });
consoleLogger.info("App started");
```

#### File Transport (Structured Logs)

```typescript showLineNumbers copy
import { FileTransport } from "@kastrax/loggers/file";

const fileLogger = createLogger({
  name: "Kastrax",
  transports: { file: new FileTransport({ path: "test-dir/test.log" }) },
  level: "warn",
});
fileLogger.warn("Low disk space", {
  destinationPath: "system",
  type: "WORKFLOW",
});
```

#### Upstash Logger (Remote Log Drain)

```typescript showLineNumbers copy
import { UpstashTransport } from "@kastrax/loggers/upstash";

const logger = createLogger({
  name: "Kastrax",
  transports: {
    upstash: new UpstashTransport({
      listName: "production-logs",
      upstashUrl: process.env.UPSTASH_URL!,
      upstashToken: process.env.UPSTASH_TOKEN!,
    }),
  },
  level: "info",
});

logger.info({
  message: "User signed in",
  destinationPath: "auth",
  type: "AGENT",
  runId: "run_123",
});
```

### Parameters

<PropertiesTable
  content={[
    {
      name: "type",
      type: "CONSOLE" | "FILE" | "UPSTASH",
      description: "Specifies the logger implementation to create.",
    },
    {
      name: "level",
      type: "LogLevel",
      isOptional: true,
      default: "INFO",
      description:
        "Minimum severity level of logs to record. One of DEBUG, INFO, WARN, or ERROR.",
    },
    {
      name: "dirPath",
      type: "string",
      isOptional: true,
      description:
        'For FILE type only. Directory path where log files are stored (default: "logs").',
    },
    {
      name: "url",
      type: "string",
      isOptional: true,
      description:
        "For UPSTASH type only. Upstash Redis endpoint URL used for storing logs.",
    },
    {
      name: "token",
      type: "string",
      isOptional: true,
      description: "For UPSTASH type only. Upstash Redis access token.",
    },
    {
      name: "key",
      type: "string",
      isOptional: true,
      default: "logs",
      description:
        "For UPSTASH type only. Redis list key under which logs are stored.",
    },
  ]}
/>
